#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int numberOfArrays(vector<int>& differences, int lower, int upper) {
        using LL = long long;
        LL start = lower, end = upper;
        for (const auto& e : differences)
        {
            start += e; end += e;
            start = max(start, (LL)lower);
            end = min(end, (LL)upper);
        }
        return max(0LL, end - start + 1);
    }
};